package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.ChildArchivesInsertRequestDTO;
import com.example.child_protection.dto.request.add.ChildArchivesParentSaveRequestDTO;
import com.example.child_protection.dto.request.add.ChildArchivesTurnSaveRequestDTO;
import com.example.child_protection.dto.request.add.ChildArchivesValuesInsertRequestDTO;
import com.example.child_protection.dto.request.find.ChildArchivesRequestDTO;
import com.example.child_protection.dto.request.update.ChildArchivesUpdateRequestDTO;
import com.example.child_protection.dto.response.ChildArchivesListResponseDTO;
import com.example.child_protection.dto.response.ChildArchivesResponseDTO;
import com.example.child_protection.service.ChildArchivesManageService;
import com.example.child_protection.service.ChildArchivesQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 儿童档案管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("childArchives")
@Api(value = "/api-childArchives", description = "儿童档案管理")
public class ChildArchivesController extends BaseController {

    @Autowired
    public ChildArchivesManageService childArchivesManageService;

    @Autowired
    public ChildArchivesQueryService childArchivesQueryService;

    @ApiOperation(value ="查询儿童档案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public ChildArchivesResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        ChildArchivesResponseDTO responseDTO = childArchivesQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询儿童档案列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public ChildArchivesListResponseDTO findList(ChildArchivesRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        ChildArchivesListResponseDTO responseDTO = childArchivesQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加儿童档案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(ChildArchivesInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childArchivesManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改儿童档案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(ChildArchivesUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childArchivesManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除儿童档案", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = childArchivesManageService.delete(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="保存儿童信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insertValues", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insertValues(ChildArchivesValuesInsertRequestDTO requestDTO)throws Exception{
        BaseResponseDTO responseDTO = childArchivesManageService.saveValues(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="保存儿童父母信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/saveParentValues", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO saveParentValues(ChildArchivesParentSaveRequestDTO requestDTO)throws Exception{
        BaseResponseDTO responseDTO = childArchivesManageService.saveParentValues(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="保存儿童转出与结案信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/saveTurnInfo", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO saveTurnInfo(ChildArchivesTurnSaveRequestDTO requestDTO)throws Exception{
        BaseResponseDTO responseDTO = childArchivesManageService.saveTurnInfo(requestDTO);
        return responseDTO;
    }

}
